package com.gzbugu.bugusys.action;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.gzbugu.bugusys.bean.PageModel;
import com.gzbugu.bugusys.dao.IBaseDAO;
import com.gzbugu.bugusys.service.FindReimburseService;
import com.opensymphony.xwork2.ActionSupport;

@Controller
public class FindReimburseAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1365922244120128515L;
	private Date start;
	private Date end;
	private Integer year;
	private Integer month;
	private String staffId;
	private PageModel page;
	private List reimburseList;

	@Resource(name = "baseDAO")
	private IBaseDAO baseDAO;
	@Resource(name = "findReimburseService")
	FindReimburseService findService;

	public String findAll() {
		page.setLineCount(findService.countReimburse().intValue());// 设置总数据量
		this.setReimburseList(findService.findReimburse(page));// 查询
		return SUCCESS;
	}

	public String findById() {
		page.setLineCount(findService.countReimburse(staffId).intValue());// 设置总数据量
		this.setReimburseList(findService.findReimburse(staffId, page));// 查询
		return SUCCESS;
	}

	public String findByDate() {
		page.setLineCount(findService.countReimburse(start, end).intValue());// 设置总数据量
		this.setReimburseList(findService.findReimburse(start, end, page));// 查询
		return SUCCESS;
	}

	public String findByMonth() {
		page.setLineCount(findService.countReimburse(year, month).intValue());// 设置总数据量
		this.setReimburseList(findService.fineReimburse(year, month, page));// 查询
		return SUCCESS;
	}

	public void validateFindById() {
		if (staffId == null)
			this.addActionError("员工编号不能为空");
		else if (baseDAO.findById(staffId,
				com.gzbugu.bugusys.fields.VoClasseFields.STAFF) == null)
			this.addActionError("员工编号不存在");
	}

	public void validateFindByDate() {
		if (start == null || end == null)
			this.addActionError("日期不能为空");
		else if (start.compareTo(end) > 0)
			this.addActionError("日期错误");
	}

	public void validateFindByMonth() {
		if (year == null || month == null || year == 0 || month == 0)
			this.addActionError("日期错误");
		else if (year < 1970 || month < 1 || month > 12)
			this.addActionError("日期错误");
	}

	public Date getStart() {
		return start;
	}

	public void setStart(Date start) {
		this.start = start;
	}

	public Date getEnd() {
		return end;
	}

	public void setEnd(Date end) {
		this.end = end;
	}

	public Integer getYear() {
		return year;
	}

	public void setYear(Integer year) {
		this.year = year;
	}

	public Integer getMonth() {
		return month;
	}

	public void setMonth(Integer month) {
		this.month = month;
	}

	public String getStaffId() {
		return staffId;
	}

	public void setStaffId(String staffId) {
		this.staffId = staffId;
	}

	public void setPage(PageModel page) {
		this.page = page;
	}

	public PageModel getPage() {
		return page;
	}

	public void setReimburseList(List reimburseList) {
		this.reimburseList = reimburseList;
	}

	public List getReimburseList() {
		return reimburseList;
	}
}
